package test3;

public class StartGirlFriend {
    public static void main(String[] args) {
        //创建四个女朋友对象
        GirlFriend girlfriend1 = new GirlFriend("可莉", 18, "玩炸弹");
        GirlFriend girlfriend2 = new GirlFriend("夜兰", 19, "跑步");
        GirlFriend girlfriend3 = new GirlFriend("纳西妲", 20, "弹钢琴");
        GirlFriend girlfriend4 = new GirlFriend("莹", 21, "沉默");

        //创建数组统一存储信息
        GirlFriend[] girlfriend= new GirlFriend[4];
        girlfriend[0] = girlfriend1;
        girlfriend[1] = girlfriend2;
        girlfriend[2] = girlfriend3;
        girlfriend[3] = girlfriend4;

        //计算平均年龄
        int aveAge=0;
        for(int i=0;i<girlfriend.length;i++){
            aveAge+=girlfriend[i].getAge();
        }
        aveAge/=girlfriend.length;
        //输出结果
        System.out.println("女朋友们的平均年龄为"+aveAge+"岁");
        System.out.println();

        //求年龄小于均值的女朋友
        System.out.println("年龄小于均值的女朋友有: ");
        for(int i=0;i<girlfriend.length;i++){
            if(girlfriend[i].getAge()<aveAge){
                //输出女朋友信息
                System.out.print("姓名: ");
                System.out.println(girlfriend[i].getName());
                System.out.print("年龄: ");
                System.out.println(girlfriend[i].getAge());
                System.out.print("爱好: ");
                System.out.println(girlfriend[i].getHobby());
                System.out.println();
            }
        }
    }

}
